class Solution
{
public:
	int matrixScore(vector<vector<int>>& A)
	{
		int numOfRows = A.size(), numOfCols = A.front().size();
		int ret = numOfRows * (1 << (numOfCols - 1));         // 最高位对结果的贡献

		for (size_t cntCol = 1; cntCol < numOfCols; cntCol++)
		{
			int nOnes = 0;
			for (size_t cntRow = 0; cntRow < numOfRows; cntRow++)
			{
				if (A[cntRow][0] == 1)
				{
					nOnes += A[cntRow][cntCol];
				}
				else
				{
					nOnes += (1 - A[cntRow][cntCol]);
				}
			}
			ret += max(nOnes, numOfRows - nOnes) * (1 << (numOfCols - 1 - cntCol));
		}
		return ret;
	}
};